package com.csmht.tododemo.controller.user;

import com.csmht.tododemo.annotation.RoleIntercept;
import com.csmht.tododemo.pojo.dto.ClassDTO;
import com.csmht.tododemo.pojo.enumeration.RoleEnum;
import com.csmht.tododemo.pojo.vo.ClassVO;
import com.csmht.tododemo.result.Result;
import com.csmht.tododemo.service.ClassService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;

import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userClassController")
@RequestMapping("/user/class")
@Slf4j
@CrossOrigin
@RoleIntercept(roles = {RoleEnum.ADMIN, RoleEnum.USER,RoleEnum.BAN_USER})
public class ClassController {

    @Resource
    private ClassService classService;


    @PutMapping
    private Result<Object> add(@RequestBody ClassDTO classDTO) {
        classService.add(classDTO);
        return Result.success();
    }

    @DeleteMapping
    private Result<Object> delete(@RequestParam List<Long> ids) {
        classService.delete(ids);
        return Result.success();
    }

    @GetMapping
    private Result<List<ClassVO>> getAll() {
        return Result.success(classService.getAll());
    }

}
